home *** CD-ROM | disk | FTP | other *** search
- #include <stdio.h>
- #include <sys/time.h>
-
- #include "fft.h"
- #include "constant.h"
-
- /*
- * Precision Dependant declarations
- */
-
- #ifdef ZOMPLEX
-
- typedef zomplex this_type;
- typedef double this_half;
-
- #define TOLERANCE DTOLERANCE
- #define THIS_GEN zgen_
- #define THIS_FFTI zfft2di
- #define THIS_SCAL zscal2d
- #define THIS_FFT zfft2d
-
- #endif
-
- #ifdef COMPLEX
-
- typedef complex this_type;
- typedef float this_half;
-
- #define TOLERANCE STOLERANCE
- #define THIS_GEN cgen_
- #define THIS_FFTI cfft2di
- #define THIS_SCAL cscal2d
- #define THIS_FFT cfft2d
-
- #endif
-
- /* */
-
- void inimat_();
- void GetArguments();
- void get_values();
-
- int min_size, max_size, inc_size, size, size_x, size_y, ld;
- this_type *pa, *pSave, *pt;
-
- int is_timing;
-
- static long z_sec, z_usec;
- static int first_time = 1;
-
- float second()
- {
- struct timeval s_val;
- struct timezone s_z;
- float time;
- long n_sec, n_usec;
- gettimeofday(&s_val, &s_z);
- n_sec = s_val.tv_sec;
- n_usec = s_val.tv_usec;
- if( first_time ) {
- z_sec = n_sec;
- z_usec = n_usec;
- first_time =0;
- }
- time = (float)(n_sec-z_sec) + (float)(n_usec -z_usec) * 1.0E-6;
- return( time );
- }
-
- main(argc,argv)
- int argc;
- char *argv[];
- {
- int i, j, k, n_total, is_wrong, nx, ny, inc, n_times, n_flops;
- double x, y, t, emax;
- this_half ratio;
-
- /* ******************************************************* */
- GetArguments( argc, argv);
- /* ******************************************************* */
-
- srandom( (123*getpid()) | 0x01);
-
- for( size=min_size ; size <= max_size ; size += inc_size) {
-
- nx = (size_x) ? size_x : size;
- ny = (size_y) ? size_y : size;
- ld = nx+1;
- n_total = (ld)*ny;
- pa = (this_type *)malloc( (n_total + ny + nx + 2*FACTOR_SPACE) * sizeof(this_type));
- if( !(pa) ) {
- fprintf( stderr, "Could not allocate ... Exiting\n");
- exit (-1);
- }
-
- fflush(stdout);
-
- printf( "%4d ", size);
-
- n_flops = (int) (5. * (double)(nx*ny) * (log((double)(nx*ny))/log(2.)));
- n_times = (int) (MAX_FLOPS / (double)n_flops);
- if(n_times < 1) n_times =1;
- ratio = 1./(double)(nx*ny);
- /* *******************************************************
- ******************************************************* */
- pSave = pa + n_total;
-
- THIS_GEN(pa, &n_total);
- pSave = THIS_FFTI( nx,ny, pSave);
-
- inc =1 ;
-
- t = second();
- for ( i = 0 ; i < n_times ; i++) {
- inc = -1;
- THIS_FFT( inc, nx, ny, pa, ld, pSave);
- inc = 1;
- THIS_FFT( inc, nx, ny, pa, ld, pSave);
- THIS_SCAL( nx, ny, ratio, pa, ld);
- }
- t = second() - t;
-
- if( is_timing)
- x = t / (double)(2*n_times);
- else
- x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
- printf("%6.3g ", x);
- /* *******************************************************
- ******************************************************* */
- printf("\n");
- free(pa);
- }
- return (0);
- }
-
- int is_random;
-
- void GetArguments( argc, argv)
- int argc;
- char *argv[];
- {
- int i, j, k;
- int nerror = 0;
-
- #define ON 1
-
- max_size = MAX_SIZE;
- min_size = MIN_SIZE;
- inc_size = INC_SIZE;
-
- is_timing = 0;
- size_x = 0;
- size_y = 0;
-
- /* ******************************************************* */
- for ( i = 1 ; (i < argc) && (nerror != ON) ; i ++ ) {
- if( argv[i][0] == '-') {
- switch ( argv[i][1]) {
- case 'x' :
- case 'X' :
- if( i+1 > argc)
- nerror = ON;
- else
- size_x = atoi( argv[++i]);
- break;
- case 'y' :
- case 'Y' :
- if( i+1 > argc)
- nerror = ON;
- else
- size_y = atoi( argv[++i]);
- break;
- case 't' :
- case 'T' :
- is_timing = 1;
- break;
- default : nerror = ON;
- }
- }
- else {
- if( i+1 > argc)
- nerror = ON;
- else {
- min_size = atoi( argv[i++]);
- max_size = atoi( argv[i++]);
- inc_size = atoi( argv[i]);
- }
- }
- }
- if( nerror == ON) {
- fprintf( stderr,
- "Usage : %s [-p(arallel)] [n_trials]\n", argv[0]);
- exit(-1);
- }
- if ( is_timing)
- fprintf( stderr, "Checking Performance in Secs\n");
- else
- fprintf( stderr, "Checking Performance in Mflops\n");
- }
-